/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.model.DeliverBill;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class DeliverBillListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"DeliverBillList.xls\"");
		HSSFSheet sheet = workbook.createSheet("list");
		List list = (List) model.get("list");
		HSSFRow r = sheet.createRow(0);
		HSSFCell c = r.createCell(0);
		r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		r.createCell(8);
		r.createCell(9);
		r.createCell(10);
		r.createCell(11);
		r.createCell(12);
		c.setCellValue(new HSSFRichTextString("送货单一览表"));
		sheet.addMergedRegion(new Region(0, 0, 0, 12));
		r = sheet.createRow(1);
		r.createCell(0).setCellValue(new HSSFRichTextString("单号"));
		r.createCell(1).setCellValue(new HSSFRichTextString("送货日期"));
		r.createCell(2).setCellValue(new HSSFRichTextString("订货单位"));
		r.createCell(3).setCellValue(new HSSFRichTextString("业务单号"));
		r.createCell(4).setCellValue(new HSSFRichTextString("订单交货日期"));
		r.createCell(5).setCellValue(new HSSFRichTextString("摘要"));
		r.createCell(6).setCellValue(new HSSFRichTextString("物流公司"));
		r.createCell(7).setCellValue(new HSSFRichTextString("物流单号"));
		r.createCell(8).setCellValue(new HSSFRichTextString("业务员"));
		r.createCell(9).setCellValue(new HSSFRichTextString("开单人"));
		r.createCell(10).setCellValue(new HSSFRichTextString("送货人"));
		r.createCell(11).setCellValue(new HSSFRichTextString("审核状态"));
		r.createCell(12).setCellValue(new HSSFRichTextString("送货状态"));
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");

		for (int os = 0; os < list.size(); ++os) {
			Object[] objs = (Object[]) list.get(os);
			DeliverBill b = (DeliverBill) objs[0];
			String exaStr = "";
			String sendStr = "";
			String bbDeli = "";
			String senderName = "";
			if (b.getExamined().equals("Y")) {
				exaStr = "已审核";
				if (b.getSended().equals("Y")) {
					sendStr = "已送出";
					senderName = b.getSenderName();
				} else {
					sendStr = "未送出";
				}
			} else {
				exaStr = "未审核";
				sendStr = "未送出";
			}

			if (objs[6] != null) {
				bbDeli = sf.format((Date) objs[6]);
			}

			r = sheet.createRow(os + 2);
			r.createCell(0).setCellValue(
					new HSSFRichTextString(b.getBillCode()));
			r.createCell(1).setCellValue(
					new HSSFRichTextString(sf.format(b.getDeliverDate())));
			r.createCell(2).setCellValue(
					new HSSFRichTextString((String) objs[1]));
			r.createCell(3).setCellValue(
					new HSSFRichTextString((String) objs[2]));
			r.createCell(4).setCellValue(new HSSFRichTextString(bbDeli));
			r.createCell(5)
					.setCellValue(new HSSFRichTextString(b.getContent()));
			r.createCell(6).setCellValue(
					new HSSFRichTextString(b.getDeliComp()));
			r.createCell(7).setCellValue(
					new HSSFRichTextString(b.getDeliCode()));
			r.createCell(8).setCellValue(
					new HSSFRichTextString((String) objs[4]));
			r.createCell(9).setCellValue(
					new HSSFRichTextString(b.getCreaterName()));
			r.createCell(10).setCellValue(new HSSFRichTextString(senderName));
			r.createCell(11).setCellValue(new HSSFRichTextString(exaStr));
			r.createCell(12).setCellValue(new HSSFRichTextString(sendStr));
		}

		ServletOutputStream arg16 = response.getOutputStream();
		workbook.write(arg16);
		arg16.flush();
		arg16.close();
	}
}